/**
 * @description 圈子 services
 */
const Opinion = require('../db/model/Opinion')

// 创建一条圈子记录
async function createOpinion(data) {
  const opinionInst = await Opinion.create(data);
  return opinionInst.dataValues;
}

// 获取圈子动态列表   
async function selectOpinionList({ limit, offset, whereOpt = {} }) {
  const { rows } = await Opinion.findAndCountAll({
    attributes: ['id', 'content', 'imgUrls', 'releaseProvinceId', 'releaseCityId'],
    where: whereOpt,
    limit,
    offset,
    order: [['id', 'DESC']],
    raw: true,
  })
  return rows
}

module.exports = {
  createOpinion,
  selectOpinionList
}
